<!DOCTYPE html>

<html>
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
        <style type="text/css">
            body {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;}
            a {color: #000077; text-decoration: none; }
            a:hover {color: #006699;}
            blockquote.synopsis {font-size: 14px;}
            blockquote.body {text-indent: 10px;}
            hr {color: #009966;}
            table {width:100%; border:0; border-collapse:collapse; padding:4px}
            table.asdu {padding: 0; margin: 0; border: 1px solid #000; font-size: 14px; color: #999}
            table.asdu td {padding: 4px; border: 1px solid #000}
            table.asdu tr.real {color:#000}
            table.asdu td:nth-child(1) {width: 20px; text-align: center}
            table.asdu td:nth-child(2) {width: 30px}
            table.asdu td:nth-child(3) {}
            div.supported {width:20px; height:20px; border: 1px; background-color: #009900;}

            td.syn {font-size: 14px; padding-top: 10px}
            td.desc {border-bottom: 1px solid #777777; padding: 5px 0 5px 10px}
            div.syn {font-family: monospace; font-size: 15px; padding: 10px 0 0 30px}
            div.desc {padding: 10px 0 0 30px; font-size:14px}
            div.box {border: none; border-width: thin; background: rgb(204,204,255); font-size: 16px;}
            h1 {font-size: 18px; font-weight: bold; color: #003366;}
            h3 {font-size: 16px; font-weight: bold; color: #003366;}
            h4 {font-size: 14px; font-weight: bold; color: #003366; margin-bottom: 0}
            h5 {font-size: 14px; font-weight: bold; color: #003366; font-style: italic; margin-bottom: 4px}
            .mono {font-family: monospace}
        </style>
        <title>IEC 60870-5-104 library API</title>
    </head>
    <body>
    <h1> IEC 60870-5-104 library API description </h1>
    <h3>Common terms</h3>
    <p> Information Object: everything is clear here. It characterized by unique
      Information Object Address (IOA) within sector containing it. IOA could
      have size of 1, 2 or 3 bytes.</p>
    <p>Sector: Group of information objects; it is characterized by unique
      Common Address of ASDU (CA). CA could have size of 1 or 2 bytes.</p>
    <p>Socket: TCP/IP socket for network data exchange, that can be
      independently Client or Server, Master or Slave. Each socket could contain
      several sectors, and each sector could belong to several sockets, but only
      one Master socket. Both IPv4 and IPv6 network protocols are supported.
      Also it is possible working over SSL.<br>
    </p>
    <h3>System requirements</h3>
    Linux, Windows with MinGW.<br>

    <h3>API</h3>
    <h5>Common functions</h5>
    <table>
      <tbody>
        <tr>
          <td class="syn"><a href="#iec_init">int iec_init(int sector_max, int
              socket_max, iec_settings_t* is, <code>syncobj_t* syncobj</code>);</a></td>
        </tr>
        <tr>
          <td class="desc">General initialization: memory allocation, common
            synchronization object and timer creation</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_free">void iec_free();</a></td>
        </tr>
        <tr>
          <td class="desc">Delete all initialized objects</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_start">int iec_start();</a></td>
        </tr>
        <tr>
          <td style="height: 15px;" class="desc">Start IEC104 running</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_stop">void iec_stop();</a></td>
        </tr>
        <tr>
          <td class="desc">Stop IEC104 running</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_wait">void iec_wait();</a></td>
        </tr>
        <tr>
          <td class="desc">Wait until IEC104 will be stopped</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_running">int iec_running();</a></td>
        </tr>
        <tr>
          <td class="desc">Check if IEC104 is running</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_lock">int iec_lock();</a></td>
        </tr>
        <tr>
          <td class="desc">Lock IEC104 running</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_lock">int iec_unlock();</a></td>
        </tr>
        <tr>
          <td class="desc">Unlock IEC104 running</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_set_object_listener">void
              iec_set_object_listener(iec_object_listener_t listener);</a></td>
        </tr>
        <tr>
          <td class="desc">Set IEC information object listener function</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_set_status_listener">void
              iec_set_status_listener(iec_status_listener_t listener);</a></td>
        </tr>
        <tr>
          <td class="desc">Set IEC status listener function</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_set_event_listener">void
              iec_set_event_listener(iec_event_listener_t listener);</a></td>
        </tr>
        <tr>
          <td class="desc">Set IEC event listener function</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_set_command_func">void
              iec_set_command_func(iec_command_func_t func);</a></td>
        </tr>
        <tr>
          <td class="desc">Set command function for IEC slave</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_set_timer_func">void
              iec_set_timer_func(iec_timer_func_t func);</a></td>
        </tr>
        <tr>
          <td class="desc">Set timer function</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_lasterror">const char* iec_lasterror();</a></td>
        </tr>
        <tr>
          <td class="desc">Return last error as string</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_strerror">const char* iec_strerror(int
              errcode);</a></td>
        </tr>
        <tr>
          <td class="desc">Return last error as string by code</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_get_sockets_count">int
              iec_get_sockets_count();</a></td>
        </tr>
        <tr>
          <td class="desc">Return sockets count<br>
          </td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_get_sectors_count">int
              iec_get_sectors_count();</a></td>
        </tr>
        <tr>
          <td class="desc">Return sectors count</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_get_objects_count">int
              iec_get_objects_count(uint32_t ca);</a></td>
        </tr>
        <tr>
          <td class="desc">Return information objects count</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_get_sectors_list">int
              iec_get_sectors_list(int index, uint16_t** result);</a></td>
        </tr>
        <tr>
          <td class="desc">Fill array with sector numbers (CA) and return
            sectors count</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_get_objects_list">int
              iec_get_objects_list(uint32_t ca, uint32_t** result);</a></td>
        </tr>
        <tr>
          <td class="desc">Fill array with information objects addresses (IOA)
            and return objects count</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_get_socket_info">int
              iec_get_socket_info(int index, iec_socket_info_t* result);</a></td>
        </tr>
        <tr>
          <td class="desc">Return information about socket<br>
          </td>
        </tr>
      </tbody>
    </table>
    <br>
    <h5>Sectors and information objects functions</h5>
    <table>
      <tbody>
        <tr>
          <td class="syn"><a href="#iec_sector_new">int iec_sector_new(const int
              ca, const int max_count, const int max_ioa);</a></td>
        </tr>
        <tr>
          <td class="desc">Create new sector</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_sector_add_info">int
              iec_sector_add_info(const int ca, uint32_t ioa, uint8_t type,
              uint8_t flags);</a></td>
        </tr>
        <tr>
          <td class="desc">Add new information object to selected sector</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_sector_add_cmd">int
              iec_sector_add_cmd(const int ca, uint32_t ioa, uint8_t flags,
              const int l_ca, uint32_t l_ioa);</a></td>
        </tr>
        <tr>
          <td class="desc">Add new command object to selected sector</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_object_duplicate">int
              iec_object_duplicate(const int ca, uint32_t ioa, const int l_ca,
              uint32_t l_ioa);</a></td>
        </tr>
        <tr>
          <td class="desc">Duplicate information object</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_object_set_value">int
              iec_object_set_value(const int ca, uint32_t ioa, void* value,
              uint16_t* qds, struct timeval* tv);</a></td>
        </tr>
        <tr>
          <td class="desc">Set information object value, quality descriptor and
            time</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_object_send_cmd">int
              iec_object_send_cmd(const int ca, uint32_t ioa, iec_variant_t*
              cmd);</a></td>
        </tr>
        <tr>
          <td class="desc">Send IEC command</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_object_get_info">int iec_object_get_info(const int
              ca, uint32_t ioa, info_object_t* info);</a></td>
        </tr>
        <tr>
          <td class="desc">Fill selected structure with full information about
            object<br>
          </td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_object_get_userdata">void*
              iec_object_get_userdata(const int ca, uint32_t ioa);</a></td>
        </tr>
        <tr>
          <td class="desc">Return user data, associated with information object</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_object_set_userdata">void
              iec_object_set_userdata(const int ca, uint32_t ioa, void*
              userdata);</a></td>
        </tr>
        <tr>
          <td class="desc">Associate user data with information object</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_sector_status">int
              iec_sector_status(const int ca);</a></td>
        </tr>
        <tr>
          <td class="desc">Return sector status</td>
        </tr>
      </tbody>
    </table>
    <br>
    <h5>Socket functions</h5>
    <table>
      <tbody>
        <tr>
          <td class="syn"><a href="#iec_socket_new">int iec_socket_new(const
              char* addr, const int port, const int count, const int flags,
              iec_settings_t* is);</a></td>
        </tr>
        <tr>
          <td class="desc">Creates new IEC104 socket</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_socket_add_sector">int
              iec_socket_add_sector(const int index, const int ca);</a></td>
        </tr>
        <tr>
          <td class="desc">Add sector to selected socket</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_socket_status">int
              iec_socket_status(const int index);</a></td>
        </tr>
        <tr>
          <td class="desc">Return socket status</td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_socket_set_allowed_list">int
              iec_socket_set_allowed_list(const int index, const char*
              addr_list);</a></td>
        </tr>
        <tr>
          <td class="desc">Set allowed ip addresses for server socket</td>
        </tr>
      </tbody>
    </table>
    <br>
    <h5>Quick configuration functions</h5>
    <table>
      <tbody>
        <tr>
          <td class="syn"><a href="#iec_save_data">int iec_save_data(const char*
              filename);</a></td>
        </tr>
        <tr>
          <td class="desc">Load from file last saved state for all information
            objects<br>
          </td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_save_data">int iec_load_data(const char*
              filename);</a></td>
        </tr>
        <tr>
          <td class="desc">Save to file state for all information objects </td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_load_config_from_files">int
              iec_load_config_from_files(const char* path, const char*
              sockets_file, const char** data_files, const iec_settings_t* is, <code>syncobj_t*
                syncobj</code>);</a></td>
        </tr>
        <tr>
          <td class="desc">Load from files configuration for all IEC104 sockets,
            sectors and information objects<br>
          </td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_load_config_from_files">int
              iec_load_config_from_mem(const char* sockets_buf, const char**
              data_bufs, const iec_settings_t* is, <code>syncobj_t* syncobj</code>);</a></td>
        </tr>
        <tr>
          <td class="desc">Load from memory buffers configuration for all IEC104
            sockets, sectors and information objects </td>
        </tr>
        <tr>
          <td class="syn"><a href="#iec_set_status_sector">int
              iec_set_status_sector(const int ca); </a></td>
        </tr>
        <tr>
          <td class="desc">Set custom sector for representation for all other
            sectors statuses (experimental)<br>
          </td>
        </tr>
      </tbody>
    </table>
    <h3>Details</h3>
    <a name="iec_init"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_init(int sector_max, int socket_max,
      iec_settings_t* is, <code>syncobj_t* syncobj</code>);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function makes general initialization: allocates
      memory, creates common synchronization object and timer.<br>
      The &lt;sector_max&gt; argument specifies maximum number of sectors to be
      created.<br>
      The &lt;socket_max&gt; argument specifies maximum number of sockets to be
      created.<br>
      The &lt;is&gt; argument points to common IEC104 settings structure that is
      described below; if NULL, will be used default constants. This settings
      specify default values; further its may be redefined for each created
      socket (see <a href="#iec_socket_new">iec_socket_new()</a>).<br>
      The &lt;syncobj&gt; field points to synchronization object, to synchronize
      IEC104 functions with other functions in an application; it could be
      semaphore or mutex (as defined in file sockets.h). If it is NULL, then
      synchronization object will be created.<br>
      <code> <br>
        typedef struct {<br>
        &nbsp;&nbsp;&nbsp; uint8_t t0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp; // IEC 104 constants<br>
        &nbsp;&nbsp;&nbsp; uint8_t t1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp; // ..<br>
        &nbsp;&nbsp;&nbsp; uint8_t t2;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp; // ..<br>
        &nbsp;&nbsp;&nbsp; uint8_t t3;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp; // ..<br>
        &nbsp;&nbsp;&nbsp; uint8_t k;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp; // .. Constant K may be zero; in this case it
        is ignored<br>
        &nbsp;&nbsp;&nbsp; uint8_t w;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp; // ..<br>
        &nbsp;&nbsp;&nbsp; uint8_t oa;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp; // Originator address<br>
        &nbsp;&nbsp;&nbsp; uint8_t ca_len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        // Length in bytes of Common address of ASDU (1,2)<br>
        &nbsp;&nbsp;&nbsp; uint8_t ioa_len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; //
        Length in bytes of Information object address (1,2,3)<br>
        } iec_settings_t;<br>
      </code></div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENOMEM, EAGAIN, EPERM<br>
    </div>
    <hr><a name="iec_free"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_free();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function deletes all initialized objects.</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_start"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_start();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function starts IEC104 processing, connects to all
      clients and makes all servers to listen, starts internal timer.</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENOMEM, or other errors that should be occur as
      result of various socket functions calls (usually EADDRINUSE).</div>
    <hr><a name="iec_stop"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_stop();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function stops IEC104 processing</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_wait"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_wait();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This wait until IEC104 will be stopped</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_running"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_running();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function checks if IEC104 is started.</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">This function shall return nonzero value if IEC104 is
      started.</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_lock"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_lock();<br>
      int iec_unlock();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This functions allow user functions to be synchronized
      with IEC104 threads.</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">Errors that should be occur by <code><tt>calling
          pthread_mutex_lock(), </tt></code><code><tt>pthread_mutex_unlock()
          (or sem_wait(), sem_post()) functions.</tt></code></div>
    <hr><a name="iec_set_object_listener"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_set_object_listener(iec_object_listener_t
      listener);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sets IEC information object listener
      function, which defined as:<br>
      <span class="mono">typedef void (*iec_object_listener_t)(const uint16_t
        ca, const uint32_t ioa, const info_object_t* info);<br>
      </span> The &lt;listener&gt; argument points to IEC data listener function<br>
      Listener will be called on every object modification<br>
      See info_object_t structure description <a href="#iec_object_get">here</a><br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_set_status_listener"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_set_status_listener(iec_status_listener_t
      listener);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sets listener function that will be called
      on sector status change (on related socket connection or disconnection),
      which is defined as:<br>
      <span style="font-family: monospace;"><span style="font-family: Verdana,Arial,Helvetica,sans-serif;">t</span></span><span class="mono">ypedef void (*iec_status_listener_t)(const uint16_t ca,
        const int status);<br>
      </span>The &lt;listener&gt; argument points to status listener function<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_set_event_listener"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_set_event_listener(iec_event_listener_t listener);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sets event listener function that will be
      called on socket events, which defined as:<br>
      <span class="mono">typedef void (*iec_event_listener_t)(const char* msg);<br>
      </span> The &lt;listener&gt; argument points to event listener function</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_set_command_func"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_set_command_func(iec_command_func_t func);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sets command function that will be called by
      slave on command receiving, which defined as:<br>
      <span class="mono">typedef int (*iec_command_func_t)(const uint16_t ca,
        uint32_t ioa, iec_variant_t* value);<br>
      </span> The &lt;func&gt; argument points to command function<br>
      Relized partially yet</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_set_timer_func"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_set_timer_func(iec_timer_func_t func);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sets user timer function that will be called
      every 1 second by internal IEC104 timer synchronously, which defined as:<br>
      <span class="mono">typedef void (*iec_timer_func_t)(time_t t);<br>
      </span> The &lt;func&gt; argument points to timer function</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="char* iec_error"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">const char* iec_lasterror();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">none</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">This function shall return pointer to last error message</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="char* iec_strerror"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">const char* iec_strerror(int errcode);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">The &lt;errcode&gt; argument specifies the error code</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">This function shall return pointer to error message by
      error code</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_get_sockets_count"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_get_sockets_count();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">Informational<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">This function shall return IEC104 sockets count</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_get_sectors_count"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_get_sectors_count();</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">Informational</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">This function shall return IEC104 sectors count</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_get_objects_count"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_get_objects_count(uint32_t ca);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">Informational<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">This function shall return IEC104 information objects
      count for selected sector. Otherwise, -1 shall be returned, and <i>errno</i>
      shall be set to indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr><a name="iec_get_sectors_list"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_get_sectors_list(int index, uint16_t** result);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">Informational<br>
      The &lt;index&gt; argument specifies socket ID, returned by <a href="index.html#iec_socket_new">iec_socket_new()</a>
      function or has negative value, in this case all sectors will be returned<br>
      The &lt;result&gt; argument points to address of buffer that will be
      filled with sequence of common addresses of ASDU.<br>
      Memory will be allocated and must be freed after its call<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      IEC104 sectors count. Otherwise, -1 shall be returned, and <i>errno</i>
      shall be set to indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENOMEM<br>
    </div>
    <hr><a name="iec_get_objects_list"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_get_objects_list(uint32_t ca, uint32_t** result);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">Informational<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
      The &lt;result&gt; argument points to address of buffer that will be
      filled with sequence of information object adresses of selected sector.<br>
      Memory will be allocated and must be freed after its call<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      IEC104 information objects count for selected sector. Otherwise, -1 shall
      be returned, and <i>errno</i> shall be set to indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENOMEM<br>
    </div>
    <hr><a name="iec_get_socket_info"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_get_socket_info(int index, iec_socket_info_t*
      result);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">Informational<br>
      The &lt;index&gt; argument specifies socket ID, returned by <a href="../../../../natali/111/333/doc/index.html#iec_socket_new">iec_socket_new()</a>
      function<br>
      The &lt;result&gt; argument points to structure to fill with some socket
      information<br>
      <span class="mono"> typedef struct {<br>
        &nbsp;&nbsp;&nbsp; uint16_t flags;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
        &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; // the same as in
        function <a href="#iec_socket_new">iec_socket_new()</a><br>
        &nbsp;&nbsp;&nbsp; uint16_t port;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
        &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // socket port<br>
        &nbsp;&nbsp;&nbsp; char address[INET6_ADDRSTRLEN];&nbsp;&nbsp; // socket
        address (if it is client)<br>
        &nbsp;&nbsp;&nbsp; uint64_t received;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
        &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; // number of received bytes<br>
        &nbsp;&nbsp;&nbsp; uint64_t transmitted;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
        &nbsp;&nbsp; &nbsp;&nbsp; // number of transmitted bytes<br>
        } iec_socket_info_t; </span><br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return 0,
      if socket is client and it is disconnected or socket is server and it has
      no active connections, 1 if socket is client or active connections number
      if socket is server. Otherwise, -1 shall be returned, and <i>errno</i>
      shall be set to indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENOMEM<br>
    </div>
    <hr><a name="iec_sector_new"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_sector_new(const int ca, const int max_count, const
      int max_ioa);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function creates new sector structure.<br>
      The &lt;ca&gt; field specifies Common Address of ASDU<br>
      The &lt;max_count&gt; field specifies maximum number of information
      objects, that should be added to this sector<br>
      The &lt;max_ioa&gt; field specifies maximum IOA value for this sector<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENONEM, EI_SECTOREXIST</div>
    <hr><a name="iec_sector_add_info"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_sector_add_info(const int ca, uint32_t ioa, uint8_t
      type, uint8_t flags);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function creates and adds new information object to
      selected sector. The sector must be already created.<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
      The &lt;ioa&gt; argument specifies Information Object Address<br>
      The &lt;type&gt; argument specifies object type<br>
      Valid types:<br>
      <ul>
        <li>IECT_SINGLE: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Single
          point value</li>
        <li>IECT_DOUBLE: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Double point
          value</li>
        <li>IECT_STEP:
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          Step position information</li>
        <li>IECT_BITSTRING: &nbsp;&nbsp;&nbsp; Bitstring of 32 bit</li>
        <li>IECT_NORMALIZED:&nbsp; Measured value, normalized value</li>
        <li>IECT_SCALED: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          Measured value, scaled value</li>
        <li>IECT_FLOAT:
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          Measured value, short floating point value</li>
        <li>IECT_INTEGRATED: &nbsp; Integrated total</li>
      </ul>
      The &lt;flags&gt; argument may be zero or could be constructed by a
      bitwise OR of flags below:<br>
      <ul>
        <li>IECF_NO_TIME: use ASDU object without modified time value sending</li>
        <li>IECF_NO_SPONT: do not transmit on value change</li>
        <li>IECF_SUBSTITUTED: manual input</li>
      </ul>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EI_SECTOR, EI_LIMIT, EI_IOA, EI_IOAEXIST, EI_TYPE</div>
    <hr><a name="iec_sector_add_cmd"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_sector_add_cmd(const int ca, uint32_t ioa, uint8_t
      flags, const int l_ca, uint32_t l_ioa);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function creates and adds new command object to
      control destination object. The controlled object must be existing.<br>
      The &lt;ca&gt; argument specifies Common address of ASDU of command object<br>
      The &lt;ioa&gt; argument specifies Information Object Address of command
      object<br>
      The &lt;type&gt; argument specifies object type<br>
      Valid types:<br>
      <ul>
        <li>IECC_SINGLE: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Single
          command</li>
        <li>IECC_DOUBLE: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Double
          command</li>
        <li>IECC_STEP:
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          Regulating step command</li>
        <li>IECC_BITSTRING: &nbsp;&nbsp;&nbsp; Bitstring 32 bit command</li>
        <li>IECC_NORMALIZED:&nbsp; Measured value, normalized value command</li>
        <li>IECC_SCALED: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          Measured value, scaled value command</li>
        <li>IECC_FLOAT:
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Measured
          value, short floating point value command</li>
      </ul>
      The &lt;flags&gt; argument may be zero or could be constructed by a
      bitwise OR of flags below:<br>
      <ul>
        <li>IECF_NO_TIME:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use
          ASDU command without modified time value sending</li>
      </ul>
      The &lt;l_ca&gt; argument specifies Common address of ASDU for controlled
      object<br>
      The &lt;l_ioa&gt; argument specifies Information Object Address for
      controlled object</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EI_SECTOR, EI_LIMIT, EI_IOA, EI_IOAEXIST, EI_TYPE</div>
    <hr><a name="iec_object_duplicate"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_object_duplicate(const int ca, uint32_t ioa, const
      int l_ca, uint32_t l_ioa);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function creates and adds destination object
      (destination object replicates source). It may be used to construct
      sectors from various objects to transmit it forward on-the-fly. The
      source object must be existing.<br>
      The &lt;ca&gt; argument specifies Common address of ASDU for source object<br>
      The &lt;ioa&gt; argument specifies Information Object Address for source
      object<br>
      The &lt;l_ca&gt; argument specifies Common address of ASDU for destination
      object<br>
      The &lt;l_ioa&gt; argument specifies Information Object Address for
      destination object<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EI_SECTOR, EI_LIMIT, EI_IOA, EI_IOAEXIST, EI_TYPE</div>
    <hr><a name="iec_object_set_value"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_object_set_value(const int ca, uint32_t ioa, void*
      value, uint16_t* qds, struct timeval* tv);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sets information object value, quality
      descriptor and modification time<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
      The &lt;ioa&gt; argument specifies Information Object Address<br>
      The &lt;value&gt; argument points to new data value, or NULL if no
      changes. Value can be char, short, int or float type depending on object
      type.<br>
      The &lt;qds&gt; argument points to new quality descriptor, or NULL if no
      changes. If QDS is not NULL, it may be combined with flags below:<br>
      <ul>
        <li>IECF_QDS_COPY:&nbsp;&nbsp; copy QDS as it is (default)</li>
        <li>IECF_QDS_SET:&nbsp;&nbsp;&nbsp;&nbsp; set bits that set in new QDS
          (bitwise OR)</li>
        <li>IECF_QDS_RESET: clear bits that set in new QDS (bitwise AND NOT)</li>
      </ul>
      The &lt;tv&gt; argument points to new object modification time, if NULL
      current time is used<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr><a name="iec_object_send_cmd"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_object_send_cmd(const int ca, uint32_t ioa,
      iec_variant_t* cmd);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sends command<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
      The &lt;ioa&gt; argument specifies Information Object Address<br>
      The &lt;cmd&gt; argument points to command. Command value can be char,
      short, int or float type depending on object type.</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr><a name="iec_object_get_info"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_object_get_info(const int ca, uint32_t ioa,
      info_object_t* info);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function fills selected structure for accepting
      information about object<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
      The &lt;ioa&gt; argument specifies Information Object Address<br>
      The &lt;info&gt; argument points to information object structure, that
      described below:<br>
      <br>
      <span class="mono">typedef struct {<br>
        &nbsp;&nbsp;&nbsp; uint8_t&nbsp;&nbsp;&nbsp;&nbsp;
        type;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; // type of object as listed <a href="#iec_sector_add_info">here</a>
        and <a href="#iec_sector_add_cmd">here</a><br>
        &nbsp;&nbsp;&nbsp; uint8_t&nbsp;&nbsp;&nbsp;&nbsp;
        qds;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // IEC-104 quality descriptor<br>
        &nbsp;&nbsp;&nbsp; struct timeval&nbsp; tv;&nbsp;&nbsp;&nbsp;&nbsp; //
        object modification time<br>
        &nbsp;&nbsp;&nbsp; iec_variant_t value;&nbsp;&nbsp;&nbsp; // value (see
        below)<br>
        &nbsp;&nbsp;&nbsp; void*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        userdata;&nbsp;&nbsp; // points to user data<br>
        } info_object_t;<br>
      </span><span class="mono"><br>
        typedef union {<br>
        &nbsp;&nbsp;&nbsp; float&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; real;<br>
        &nbsp;&nbsp;&nbsp; int32_t&nbsp;&nbsp;&nbsp;&nbsp; int32;<br>
        &nbsp;&nbsp;&nbsp; uint32_t&nbsp;&nbsp;&nbsp; uint32;<br>
        &nbsp;&nbsp;&nbsp; int16_t&nbsp;&nbsp;&nbsp;&nbsp; int16;<br>
        &nbsp;&nbsp;&nbsp; uint16_t&nbsp;&nbsp;&nbsp; uint16;<br>
        &nbsp;&nbsp;&nbsp; int8_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int8;<br>
        &nbsp;&nbsp;&nbsp; uint8_t&nbsp;&nbsp;&nbsp;&nbsp; uint8;<br>
        } iec_variant_t;</span><br>
      <br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr><a name="iec_object_get_userdata"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void* iec_object_get_userdata(const int ca, uint32_t ioa);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function returns pointer to user data, associated
      with the information object<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
      The &lt;ioa&gt; argument specifies Information Object Address</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      pointer to user data. Otherwise, NULL shall be returned.</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_object_set_userdata"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">void iec_object_set_userdata(const int ca, uint32_t ioa,
      void* userdata);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function associates user data with the information
      object<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
      The &lt;ioa&gt; argument specifies Information Object Address<br>
      The &lt;userdata&gt; argument points to user data</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">none</div>
    <h4>ERRORS</h4>
    <div class="desc">none</div>
    <hr><a name="iec_sector_status"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_sector_status(const int ca);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function uses sector status for checkings <br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      status of master socket, associated with sector (1 if it is connected,
      else 0). Otherwise, -1 shall be returned, and <i>errno</i> shall be set
      to indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr><a name="iec_socket_new"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_socket_new(const char* addr, const int port, const
      int count, const int flags, iec_settings_t* is);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function creates new IEC104 socket<br>
      The &lt;addr&gt; argument specifies connection address for client, bind
      address for server<br>
      The &lt;port&gt; argument specifies socket port<br>
      The &lt;count&gt; argument specifies maximum number of sectors, that could
      be associated with this socket<br>
      The &lt;flags&gt; argument must be constructed by a bitwise OR of flags
      below:<br>
      <ul>
        <li>IECF_S_IPV6:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use ipv6, otherwise
          ipv4</li>
        <li>IECF_S_CLIENT:&nbsp;&nbsp; client socket</li>
        <li>IECF_S_SERVER:&nbsp; server socket</li>
        <li>IECF_S_MASTER: master mode (default for client)</li>
        <li>IECF_S_SLAVE:&nbsp;&nbsp;&nbsp; slave mode (default for server)</li>
        <li>IECF_S_SSL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use SSL socket
          (only available if application is compiled with "#define SSL_SUPPORT"
          uncommented in sockets.h file, and linked with -lssl -lcrypto
          libraries)</li>
      </ul>
      Flags IECF_S_CLIENT with IECF_S_SERVER, and IECF_S_MASTER with
      IECF_S_SLAVE evidently cannot be combined.<br>
      The &lt;is&gt; argument means the same, as in function <a href="#iec_init">iec_init()</a>.<br>
      <br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall non
      negative IEC socket ID. Otherwise, -1 shall be returned, and <i>errno</i>
      shall be set to indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENOMEM, EI_LIMIT, EI_SOCKETEXIST</div>
    <hr><a name="iec_socket_add_sector"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_socket_add_sector(const int index, const int ca);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function adds sector to selected socket. One socket
      could contain several sectors, and one sector can belongs to several
      sockets, but only one Master socket.<br>
      The &lt;index&gt; argument specifies socket ID, returned by <a href="#iec_socket_new">iec_socket_new()</a>
      function<br>
      The &lt;ca&gt; argument specifies Common address of ASDU</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EI_SECTOR, EI_SOCKET, EI_LIMIT, EI_SECTOREXIST,
      EI_MASTEREXIST</div>
    <hr><a name="iec_socket_status"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_socket_status(const int index);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function checks socket status<br>
      The &lt;index&gt; argument specifies socket ID, returned by <a href="file:///home/natali/111/333/doc/index.html#iec_socket_new">iec_socket_new()</a>
      function</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return 1
      if socket is active (client is connected or server is listening), else
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr><a name="iec_socket_set_allowed_list"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_socket_set_allowed_list(const int index, const
      char* addr_list);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">This function sets allowed IP addresses for server socket;
      connections from all unlisted addresses will be broken immediatily. If the
      function is not called all connections are allowed.<br>
      The &lt;index&gt; argument specifies socket ID, returned by <a href="file:///home/natali/111/333/doc/index.html#iec_socket_new">iec_socket_new()</a>
      function<br>
      The &lt;addr_list&gt; argument points to comma separated list of IP
      addresses; if NULL, then all connections are allowed</div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr><a name="iec_save_data"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_save_data(const char* filename);<br>
      int iec_load_data(const char* filename);<br>
    </div>
    <h4>DESCRIPTION</h4>
    <div class="desc">These functions allow to save and to restore state of all
      information objects<br>
      The &lt;code&gt; argument specifies name of file for save to or load from<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">ENOMEM, or other errors that should occur by calling file
      I/O functions</div>
    <hr><a name="iec_load_config_from_files"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_load_config_from_files(const char* path, const
      char* sockets_file, const char** data_files, const iec_settings_t* is, <code>syncobj_t*
        syncobj</code>);<br>
      int iec_load_config_from_mem(const char* sockets_buf, const char**
      data_bufs, const iec_settings_t* is, <code>syncobj_t* syncobj</code>);<br>
    </div>
    <h4>DESCRIPTION</h4>
    <div class="desc">These functions allow quick configuration of all IEC104
      sockets, sectors and information objects.<br>
      Function iec_load_config_from_files() arguments:<br>
      The &lt;path&gt; argument specifies directory name, where all
      configuration files are located<br>
      The &lt;sockets_file&gt; argument specifies name of sockets configuration
      file; its format is described below<br>
      The &lt;data_files&gt; argument specifies array of names of information
      objects configuration files, last pointer must be NULL; its format is
      described below<br>
      The &lt;is&gt; and &lt;syncobj&gt; arguments mean the same as in function
      <a href="#iec_init">iec_init()</a><br>
      Function iec_load_config_from_mem() arguments:<br>
      The &lt;sockets_buf&gt; argument points to sockets configuration memory
      buffer; its format is described below<br>
      The &lt;data_bufs&gt; argument specifies array of pointers to information
      objects configuration memory buffers, last pointer must be NULL; its
      format is described below<br>
      The &lt;is&gt; argument means the same as in function <a href="index.html#iec_init">iec_init()</a><br>
      <br>
      Configuration format: &lt;Tab&gt; delimited CSV; fields are described
      below<br>
      <br>
      Sockets:<br>
      <ol>
        <li>Flag: 0 (unused) or 1 (used)</li>
        <li>Socket port<br>
        </li>
        <li>Socket IP address (for client)</li>
        <li>IEC104 type: 1 (Master) or 0 (Slave)</li>
        <li>Socket type: 1 (Client) or 0 (Server)</li>
        <li>Options:&nbsp; [op1=value1[,op2=value2...]]<br>
          Valid options (case insensitive):<br>
          <ul>
            <li>T0, T1, T2, T3, K, W - IEC104 constants; constant K may be zero;
              in this case it is ignored</li>
            <li>CA - CA (Common Address of ASDU) length (1 or 2)</li>
            <li>IOA - IOA (Information Object Address) length (1, 2 or 3)</li>
            <li>IPV - IP version (4 or 6)</li>
            <li>CIR - Common Interrogation Required (0 or 1)</li>
            <li>SSL - see <a href="#iec_socket_new">iec_socket_new()</a>
              description (0 or 1)<br>
            </li>
          </ul>
          If options are not defined then used default values<br>
          Example: t0=10,t1=15,t2=10,t3=30,w=8,k=12,ca=2,ioa=3,cir=0 (defaults)</li>
        <li>List of CA, related to the socket; for example: 1,5,6,10..15,50</li>
        <li>If it is SERVER socket, then list of allowed client IPs (comma
          separated), or empty string if all clients allowed</li>
        <li>Here may be some other fields, that used by application, comments
          etc.</li>
      </ol>
      Information objects:<br>
      <ol>
        <li>Flag: 0 (unused or manual input) or 1 (real)</li>
        <li>CA (Common Address of ASDU)</li>
        <li>IOA (Information Object Address)</li>
        <li>Object type:<br>
          Valid types:
          <ol>
            <li>Single point info</li>
            <li>Double point info</li>
            <li>Step value</li>
            <li>Bitstring of 32 bit</li>
            <li>Measured normalized value</li>
            <li>Measured scaled value</li>
            <li>Measured float value</li>
            <li>Integrated value</li>
          </ol>
        </li>
        <li>&nbsp;Linked CA/IOA (if needed) for telecontrol or DATA duplication
          (if a field is zero or empty string use the current CA or IOA;&nbsp;
          if both are zero or empty string, option is disabled)</li>
        <li>Here may be some other fields</li>
      </ol>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL, ENOMEM, EI_TOOBIG, EI_LIMIT, EI_SOCKET, EI_SECTOR,
      EI_IOA, EI_TYPE, EI_SOCKETEXIST, EI_SECTOREXIST, EI_IOAEXIST,
      EI_MASTEREXIST, EI_SYNTAX, EI_OPTIONS, or in case of use
      iec_load_config_from_files() function, some other errors that should be
      occur for file I/O functions<br>
    </div>
    <hr><a name="iec_set_status_sector"></a>
    <h4>SYNOPSIS</h4>
    <div class="syn">int iec_set_status_sector(const int ca);</div>
    <h4>DESCRIPTION</h4>
    <div class="desc">Experimental<br>
      This function sets custom sector for representation of all other sectors
      statuses. All its information objects has IEC-104 type M_ST_TB_1.<br>
      Its values is combined with bits:<br>
      IEC_SECTOR_IN: sector relates to master socket<br>
      IEC_SECTOR_OUT: sector relates to slave socket<br>
      IEC_SECTOR_ERROR: parent socket is inactive<br>
      Currently only available with configuration functions. In this case must
      be called before calling iec_load_config_from_files() or
      iec_load_config_from_mem().<br>
      The &lt;ca&gt; argument specifies Common address of ASDU<br>
    </div>
    <h4>RETURN VALUE</h4>
    <div class="desc">Upon successful completion, this function shall return
      zero. Otherwise, -1 shall be returned, and <i>errno</i> shall be set to
      indicate the error.</div>
    <h4>ERRORS</h4>
    <div class="desc">EINVAL</div>
    <hr> <br>
    <h3>Currently realized ASDU types</h3>
    <table class="asdu">
      <tbody>
        <tr class="real">
          <td>x</td>
          <td>1<br>
          </td>
          <td>M_SP_NA_1</td>
          <td>Single-point information</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>2<br>
          </td>
          <td>M_SP_TA_1</td>
          <td>Single-point information with time tag</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>3<br>
          </td>
          <td>M_DP_NA_1</td>
          <td>Double-point information</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>4<br>
          </td>
          <td>M_DP_TA_1</td>
          <td>Double-point information with time tag</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>5<br>
          </td>
          <td>M_ST_NA_1</td>
          <td>Step position information</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>6<br>
          </td>
          <td>M_ST_TA_1</td>
          <td>Step position information with time tag</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>7<br>
          </td>
          <td>M_BO_NA_1</td>
          <td>Bitstring of 32 bit</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>8<br>
          </td>
          <td>M_BO_TA_1</td>
          <td>Bitstring of 32 bit with time tag</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>9<br>
          </td>
          <td>M_ME_NA_1</td>
          <td>Measured value, normalised value</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>10<br>
          </td>
          <td>M_ME_TA_1</td>
          <td>Measured value, normalized value with time tag</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>11<br>
          </td>
          <td>M_ME_NB_1</td>
          <td>Measured value, scaled value</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>12<br>
          </td>
          <td>M_ME_TB_1</td>
          <td>Measured value, scaled value wit time tag</td>
        </tr>
        <tr class="real">
          <td>x</td>
          <td>13<br>
          </td>
          <td>M_ME_NC_1</td>
          <td>Measured value, short floating point number</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>14<br>
          </td>
          <td>M_ME_TC_1</td>
          <td>Measured value, short floating point number with time tag</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>15<br>
          </td>
          <td>M_IT_NA_1</td>
          <td>Integrated totals</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>16<br>
          </td>
          <td>M_IT_TA_1</td>
          <td>Integrated totals with time tag</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>17<br>
          </td>
          <td>M_EP_TA_1</td>
          <td>Event of protection equipment with time tag</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>18<br>
          </td>
          <td>M_EP_TB_1</td>
          <td>Packed start events of protection equipment with time tag</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>19<br>
          </td>
          <td>M_EP_TC_1</td>
          <td>Packed output circuit information of protection equipment with
            time tag</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>20<br>
          </td>
          <td>M_PS_NA_1</td>
          <td>Packed single point information with status change detection</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>21<br>
          </td>
          <td>M_ME_ND_1</td>
          <td>Measured value, normalized value without quality descriptor</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>30<br>
          </td>
          <td>M_SP_TB_1</td>
          <td>Single-point information with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>31<br>
          </td>
          <td>M_DP_TB_1</td>
          <td>Double-point information with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>32<br>
          </td>
          <td>M_ST_TB_1</td>
          <td>Step position information with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>33<br>
          </td>
          <td>M_BO_TB_1</td>
          <td>Bitstring of 32 bit with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>34<br>
          </td>
          <td>M_ME_TD_1</td>
          <td>Measured value, normalised value with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>35<br>
          </td>
          <td>M_ME_TE_1</td>
          <td>Measured value, scaled value with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>36<br>
          </td>
          <td>M_ME_TF_1</td>
          <td>Measured value, short floating point number with time tag
            CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>37<br>
          </td>
          <td>M_IT_TB_1</td>
          <td>Integrated totals with time tag CP56Time2a</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>38<br>
          </td>
          <td>M_EP_TD_1</td>
          <td>Event of protection equipment with time tag CP56Time2a</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>39<br>
          </td>
          <td>M_EP_TE_1</td>
          <td>Packed start events of protection equipment with time tag
            CP56Time2a</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>40<br>
          </td>
          <td>M_EP_TF_1</td>
          <td>Packed output circuit information of protection equipment with
            time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>45<br>
          </td>
          <td>C_SC_NA_1</td>
          <td>Single command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>46<br>
          </td>
          <td>C_DC_NA_1</td>
          <td>Double command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>47<br>
          </td>
          <td>C_RC_NA_1</td>
          <td>Regulating step command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>48<br>
          </td>
          <td>C_SE_NA_1</td>
          <td>Set-point Command, normalised value</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>49<br>
          </td>
          <td>C_SE_NB_1</td>
          <td>Set-point Command, scaled value</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>50<br>
          </td>
          <td>C_SE_NC_1</td>
          <td>Set-point Command, short floating point number</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>51<br>
          </td>
          <td>C_BO_NA_1</td>
          <td>Bitstring 32 bit command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>58<br>
          </td>
          <td>C_SC_TA_1</td>
          <td>Single command with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>59<br>
          </td>
          <td>C_DC_TA_1</td>
          <td>Double command with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>60<br>
          </td>
          <td>C_RC_TA_1</td>
          <td>Regulating step command with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>61<br>
          </td>
          <td>C_SE_TA_1</td>
          <td>Measured value, normalised value command with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>62<br>
          </td>
          <td>C_SE_TB_1</td>
          <td>Measured value, scaled value command with time tag CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>63<br>
          </td>
          <td>C_SE_TC_1</td>
          <td>Measured value, short floating point number command with time tag
            CP56Time2a</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>64<br>
          </td>
          <td>C_BO_TA_1</td>
          <td>Bitstring of 32 bit command with time tag CP56Time2a</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>70<br>
          </td>
          <td>M_EI_NA_1</td>
          <td>End of Initialization</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>100<br>
          </td>
          <td>C_IC_NA_1</td>
          <td>Interrogation command</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>101<br>
          </td>
          <td>C_CI_NA_1</td>
          <td>Counter interrogation command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>102<br>
          </td>
          <td>C_RD_NA_1</td>
          <td>Read command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>103<br>
          </td>
          <td>C_CS_NA_1</td>
          <td>Clock synchronisation command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>104<br>
          </td>
          <td>C_TS_NA_1</td>
          <td>Test command</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>105<br>
          </td>
          <td>C_RP_NA_1</td>
          <td>Reset process command</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>106<br>
          </td>
          <td>C_CD_NA_1</td>
          <td>Delay acquisition command</td>
        </tr>
        <tr class="real">
          <td>x<br>
          </td>
          <td>107<br>
          </td>
          <td>C_TS_TA_1</td>
          <td>Test command with time tag CP56Time2a</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>110<br>
          </td>
          <td>P_ME_NA_1</td>
          <td>Parameter of measured values, normalized value</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>111<br>
          </td>
          <td>P_ME_NB_1</td>
          <td>Parameter of measured values, scaled value</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>112<br>
          </td>
          <td>P_ME_NC_1</td>
          <td>Parameter of measured values, short floating point number</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>113<br>
          </td>
          <td>P_AC_NA_1</td>
          <td>Parameter activation</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>120<br>
          </td>
          <td>F_FR_NA_1</td>
          <td>File ready</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>121<br>
          </td>
          <td>F_SR_NA_1</td>
          <td>Section ready</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>122<br>
          </td>
          <td>F_SC_NA_1</td>
          <td>Call directory, select file, call file, call section</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>123<br>
          </td>
          <td>F_LS_NA_1</td>
          <td>Last section, last segment</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>124<br>
          </td>
          <td>F_FA_NA_1</td>
          <td>ACK file, ACK section</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>125<br>
          </td>
          <td>F_SG_NA_1</td>
          <td>Segment</td>
        </tr>
        <tr>
          <td><br>
          </td>
          <td>126<br>
          </td>
          <td>F_DR_TA_1</td>
          <td>Directory</td>
        </tr>
      </tbody>
    </table>
    </body>
</html>


